<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <!-- <el-table-column prop="title" label="封面图" width="80">
        <template slot-scope="{ row }">
          <img
            class="cover-img"
            :src="row.fileId ? row.sysAttachment.httpUrl : defaultCourseImg"
            alt=""
          />
        </template>
      </el-table-column> -->
      <el-table-column prop="name" label="视频名称">
        <template slot-scope="{ row }">
          <el-link :underline="false">{{ row.name }}</el-link>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="strategyDate" label="融入策略(时间)" width="140">
           <template slot-scope="{ row }">
                <div>
                    {{row.strategyDate=='undefined'?'--':row.strategyDate}}
                </div>
            </template>
      </el-table-column> -->
      <el-table-column prop="strategy" label="学时">
        <template slot-scope="{ row }">
            {{ row.strategy || 0 }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="{ row }">
          <el-button-group>
            <!--  <el-button type="primary" size="mini" @click="handleBrowse(row)">
              预览
            </el-button>
            <el-button type="primary" size="mini" @click="handleManage(row)">
              管理
            </el-button>
            <el-button type="primary" size="mini" @click="handleUpdata(row)">
              上传附件
            </el-button> -->
            <el-button type="primary" size="mini" @click="handleEdit(row)">
              编辑
            </el-button>
            <el-button type="danger" size="mini" @click="handleDelete(row)">
              删除
            </el-button>
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <!-- <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    /> -->
  </div>
</template>
<script>
import {
  sysKnowledgeQuery,
  sysKnowledgeDelete,
} from '@/api/admin/courseLibrary/sysKnowledge.js'
import Bus from '@/utils/bus.js'
import webinfo from '@/mixins/webinfo.js'
export default {
  mixins: [webinfo],
  data() {
    return {
      type: this.$route.meta.type,
      listQuery: {
        page: 1,
        limit: 10,
        courseId: this.$store.getters.courseId,
      },
      tableData: [],
      pageObj: {},
    }
  },
  watch: {
    tableData(val) {},
  },
  mounted() {
    this.getList()
    Bus.$on('refreshKnowledgeList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshKnowledgeList')
  },
  methods: {
    getList() {
      sysKnowledgeQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.tableData.forEach((e) => {
          if (e.strategy) {
            e.strategyDate = e.strategy.split(',')[0]
            e.strategyTxt = e.strategy.split(',')[1]
          }
        })
        this.pageObj = res.data
        Bus.$emit('refreshKnowledgeId', res.data.data)
      })
    },
    //附件管理
    handleManage(row) {
      Bus.$emit('showDialogKnowledgeAdd', { type: 'edit', row })
      //   this.$store.commit("SETKNOLEDGE", row);
      //   this.$router.push({ name: "knowledge-setting" });
    },
    //编辑
    handleEdit(row) {
      Bus.$emit('showDialogKnowledgeAdd', { type: 'edit', row })
    },
    //浏览
    handleBrowse(row) {
      this.$store.commit('SETKNOLEDGE', row)
      let name = 'knowdedge-detail'
      if (this.type == 1) {
        name = 'knowdedge-detail'
      }
      if (this.type == 3) {
        name = 'arms-knowdedge'
      }
      if (this.type == 4) {
        name = 'topic-knowdedge-detail'
      }
      let routeUrl = this.$router.resolve({
        name: name,
        query: { id: row.id },
      })
      window.open(routeUrl.href, '_blank')
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      sysKnowledgeDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped>
.cover-img {
  display: block;
  width: 60px;
  height: 40px;
}
.knowledge-strategy {
  max-width: 200px;
}
</style>